/**
 * 管理员
 * @author chenyi
 * @email 228112142@qq.com
 * @date 2018-06-12 08:53:21
 */

/**数据渲染对象*/
var Custom = {
    /**
     * 渲染状态列
     * @param rowData    行数据
     * @param renderData 渲染后的列
     * @param index      当前数据序列
     * @param value      当前对象值
     */
    status: function (rowData,renderData, index, value) {
        var checked=rowData.status==="1"?"checked":"";
        var url=rowData.status==="1"?"/sys/user/limit":"/sys/user/enable";
        value='<input type="checkbox" lay-filter="status"  lay-url="'+url+'" '+checked+' data-id="'+rowData.userId+'" name="status" lay-skin="switch" lay-text="启用|禁用">';
        return value;
    },
    img: function (rowData,renderData, index, value) {
        // return  '<img style="max-height:30px;max-width:100px;cursor:pointer" src="'+$t.getImgBaseUrl()+value+'" >';
        return  '<img style="max-height:30px;max-width:100px;cursor:pointer" src="'+value+'" >';
    },
    name: function (rowData,renderData, index, value) {
        return'<span class="click-span" onclick="detailOne(\''+"/sys/user/info/"+rowData.userId+'\',)"  >'+value+'</span>';
    },
    bar:function(rowData,renderData, index, value){
        var btn=[
            '<button  lay-url="/sys/user/info/'+rowData.userId+'" lay-event="info" class="layui-btn layui-btn-primary layui-btn-xs">查看</button>',
            '<button  lay-url="/sys/user/edit/'+rowData.userId+'" lay-event="edit" class="layui-btn layui-btn-xs">修改</button>',
            '<button  onclick="deleteOne(\''+"删除"+'\',\''+"/sys/user/delete"+'\',\''+rowData.userId+'\')" class="layui-btn layui-btn-delete layui-btn-xs">删除</button>'
        ].join("");
        return btn;
    }
};


function initPassword(table_id, url) {
    //获取选中的id
    var ids = getCheckIds(table_id);
    if (ids.length === 0) {
        Msg.info("至少选择一条数据");
        return;
    }
    if (ids.length>0) {
        confirm("确认初始化密码？", function () {
            $.ajax({
                type: "post",
                url: url,
                contentType: "application/json",
                data: JSON.stringify(ids),
                async: false,
                dataType: "json",
                success: function (R) {
                    if (R.code === 0) {
                        $(".search-btn").click();
                        Msg.success('操作成功');
                    } else {
                        Msg.error(R.msg);
                    }
                },
                error: function () {
                    Msg.error("系统错误");
                }
            });
        });
    }
}

/**跳转到添加页面*/
function add(url) {
    //$("body").load(url);
    //type：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
    parent.layer.open({
        type: 2,
        title: '添加',
        shadeClose: false,
        shade: [0.3, '#000'],
        maxmin: true, //开启最大化最小化按钮
        area: ['893px', '600px'],
        content: url
    });
}
/**跳转到修改页面*/
function edit(table_id, url) {
    var id = getSelectedRow(table_id, url);
    if (id != null) {
        parent.layer.open({
            type: 2,
            title: '修改',
            shadeClose: false,
            shade: [0.3, '#000'],
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '600px'],
            content: url + "/" + id
        });
    }
}
/**删除*/
function deleteBatch(table_id, url) {
    //获取选中的id
    var ids = getSelectedRows(table_id);
    if (ids != null) {
        confirm("确认删除？", function () {
            $.ajax({
                type: "post",
                url: url,
                contentType: "application/json",
                data: JSON.stringify(ids),
                async: false,
                dataType: "json",
                success: function (R) {
                    if (R.code === 0) {
                        Msg.success('操作成功');
                        $(".search-btn").click();
                    } else {
                        Msg.error(R.msg);
                    }
                },
                error: function () {
                    Msg.error("系统繁忙");
                }
            });
        });

    }

}